package com.linjian.togetherbirthday.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.linjian.togetherbirthday.MainActivity;
import com.linjian.togetherbirthday.R;
import com.linjian.togetherbirthday.activity.SplashActivity;
import com.linjian.togetherbirthday.base.BaseFragment;
import com.linjian.togetherbirthday.utils.SharedPreferencesUtil;
import com.yuntongxun.plugin.common.SDKCoreHelper;

public class SetFragment extends BaseFragment implements View.OnClickListener {

    private ImageView backIv;
    private TextView titleTv,rightTv,changePwdTv,changePhoneTv,exitTv;

    private MainActivity mainActivity;

    public static SetFragment newInstance() {
        SetFragment setFragment = new SetFragment();
        Bundle bundle = new Bundle();
//        bundle.putInt(Integer.class.getName(), resId);
        setFragment.setArguments(bundle);
        return setFragment;
    }

    @Override
    protected int setView() {
        return R.layout.fragment_set;
    }

    @Override
    protected void init(View view) {
        backIv = view.findViewById(R.id.layout_head_back_iv);
        titleTv = view.findViewById(R.id.layout_head_title_tv);
        rightTv = view.findViewById(R.id.layout_head_right_tv);
        changePwdTv = view.findViewById(R.id.set_change_pwd_tv);
        changePhoneTv = view.findViewById(R.id.set_change_phone_tv);
        mainActivity = (MainActivity) getActivity();
        exitTv = view.findViewById(R.id.exit_login_tv);
    }

    @Override
    protected void initData(Bundle savedInstanceState) {
        titleTv.setText("设置");
        rightTv.setVisibility(View.GONE);
        setListener();
    }
    private void setListener() {
        backIv.setOnClickListener(this);
        changePhoneTv.setOnClickListener(this);
        changePwdTv.setOnClickListener(this);
        exitTv.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.layout_head_back_iv:
                getActivity().getSupportFragmentManager().popBackStack();
                break;
            case R.id.set_change_pwd_tv:
                mainActivity.replaceFragment("ChangePasswrodFragment","");
                break;
            case R.id.set_change_phone_tv:
                mainActivity.replaceFragment("ChangePhoneFragment","");
                break;
            case R.id.exit_login_tv:
                SDKCoreHelper.logout();
                SharedPreferencesUtil.clear(getActivity());
                getActivity().startActivity(new Intent(getActivity(),SplashActivity.class));
                break;
        }
    }
}
